<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

			<%@ include file="/include/gnb.jsp"%>
			<!-- Main Start -->
			<div id="maincontainer">
				<!-- LeftMenu Start -->
				<div id="leftmenu">
					<%@ include file="/include/lnb.jsp"%>
				</div>
				<!-- Contants Start -->
				<div id="contants">
					<div class="height_10p"></div>
					<form id="commonForm" name="commonForm" method="post">
						<input type="hidden" id="_groupId" name="_groupId" value="${_groupId}" />
						<input type="hidden" id="_menuId" name="_menuId" value="${_menuId}" />
						<input type="hidden" id="_menuNm" name="_menuNm" value="${_menuNm}" />
						<input type="hidden" id="_menuAuth" name="_menuAuth" value="${_menuAuth}" />
						<input type="hidden" id="_prevFirstCode" name="_prevFirstCode" value="${_prevFirstCode}" />
						<input type="hidden" id="_prevSecondCode" name="_prevSecondCode" value="${_prevSecondCode}" />
						<input type="hidden" id="_prevThirdCode" name="_prevThirdCode" value="${_prevThirdCode}" />
					</form>
					<div id="ajaxDivList" class="noborder"></div>
				</div>
				<!-- Contants End -->
			</div>
		</div>
		<!-- Footer Start -->
		<div id="footer">
			<%@ include file="/include/footer.jsp"%>
		</div>
	</div>

<script>
var url = "categoryMgmt.action";
var params = "target=cmList";
var targetElement = "ajaxDivList";

var pmModule = {
		loadList: function() {
			var rParams = params + "&" + $("#commonForm").serialize() + ($("#loadCheck").val() == "OK" ? ($("#isNew").val() == "Y" ? "&searchVal1=" + $("#searchVal1").val() : "&" + $("#searchForm").serialize()) : "");

			this.makeList(url, rParams);
		},
		
		setBinding: function() {
		},
		
		setUnbinding: function() {
		},
		
		select: function(categoryId, categoryType) {
			var use = $("#use_" + categoryId);
			if (use.val() == "N") {
				alert("해당 카테고리를 사용할 수 없습니다. 사용 여부를 변경하여 주십시오.");
				$("#_prevFirstCode").val("");
				$("#_prevSecondCode").val("");
				$("#_prevThirdCode").val("");
				$("#firstForm #first_" + categoryId).removeClass("selected");
				$("#secondForm #second_" + categoryId).removeClass("selected");
				$("#thirdForm #third_" + categoryId).removeClass("selected");
				return;
			}

			$("#addFirstDiv").hide();
			$("#addSecondDiv").hide();
			$("#addThirdDiv").hide();
			this.resetAdd("1");
			this.resetAdd("2");
			this.resetAdd("3");
			
			if (categoryType == "1") {
				$("#firstForm .selected").removeClass("selected");
				$("#firstForm #first_" + categoryId).addClass("selected");
				
				$("#secondForm #categoryFirst").val(categoryId);
				$("#thirdForm #categoryFirst").val(categoryId);
				
				$("#rSecond").removeClass("nodisplay");
				$("#rSecond .ulMenu").addClass("nodisplay");
				$(".first_" + categoryId).removeClass("nodisplay");
				
				$("#rThird").addClass("nodisplay");
				
				$("#_prevFirstCode").val(categoryId);
			} else if (categoryType == "2") {
				$("#secondForm .selected").removeClass("selected");
				$("#secondForm #second_" + categoryId).addClass("selected");
				
				$("#thirdForm #categorySecond").val(categoryId);
				
				$("#rThird").removeClass("nodisplay");
				$("#rThird .ulMenu").addClass("nodisplay");
				$(".second_" + categoryId).removeClass("nodisplay");
				
				$("#_prevSecondCode").val(categoryId);
			} else {
			}
		},
		
		setAdd: function(categoryType) {
			this.resetAdd(categoryType);
			if (categoryType == "1") {
				$("#addFirstDiv").removeClass("nodisplay")
										.css({
											"position":"absolute", 
											"top":($("#rFirst").offset().top + $(".ulPlusMenu").innerHeight()), 
											"width":$("#rFirst").css("width"),
											"border":"1px dotted #666"
										})
										.hide()
										.slideDown(200);
			} else if (categoryType == "2") {
				$("#addSecondDiv").removeClass("nodisplay")
										.css({
											"position":"absolute", 
											"top":($("#rSecond").offset().top + $(".ulPlusMenu").innerHeight()), 
											"width":$("#rSecond").css("width"),
											"border":"1px dotted #666"
										})
										.hide()
										.slideDown(200);
			} else {
				$("#addThirdDiv").removeClass("nodisplay")
										.css({
											"position":"absolute", 
											"top":($("#rThird").offset().top + $(".ulPlusMenu").innerHeight()), 
											"width":$("#rThird").css("width"),
											"border":"1px dotted #666"
										})
										.hide()
										.slideDown(200);
			}
		},
		
		setModify: function(categoryId, categoryNm, categoryDesc, useYn, categoryType, menuGroupId) {
			this.setAdd(categoryType);
			if (categoryType == "1") {
				$("#firstForm #isNew").val("N");
				$("#firstForm #categoryId").val(categoryId);
				$("#firstForm #categoryNm").val(categoryNm);
				$("#firstForm #categoryDesc").val(categoryDesc);
				$("#firstForm #menuGroupId").val(menuGroupId);
				if (useYn == "N") {
					$("#firstForm #useYn2").click();
				}
	
				$("#firstForm .selected").removeClass("selected");
				$("#firstForm #first_" + categoryId).addClass("selected");
				
				$("#_prevFirstCode").val(categoryId);
			} else if (categoryType == "2") {
				$("#secondForm #isNew").val("N");
				$("#secondForm #categoryId").val(categoryId);
				$("#secondForm #categoryNm").val(categoryNm);
				$("#secondForm #categoryDesc").val(categoryDesc);
				$("#secondForm #menuGroupId").val(menuGroupId);
				if (useYn == "N") {
					$("#secondForm #useYn2").click();
				}

				$("#secondForm .selected").removeClass("selected");
				$("#secondForm #second_" + categoryId).addClass("selected");
				
				$("#_prevSecondCode").val(categoryId);
			} else {
				$("#thirdForm #isNew").val("N");
				$("#thirdForm #categoryId").val(categoryId);
				$("#thirdForm #categoryNm").val(categoryNm);
				$("#thirdForm #categoryDesc").val(categoryDesc);
				$("#thirdForm #menuGroupId").val(menuGroupId);
				if (useYn == "N") {
					$("#thirdForm #useYn2").click();
				}

				$("#thirdForm .selected").removeClass("selected");
				$("#thirdForm #third_" + categoryId).addClass("selected");
				
				$("#_prevThirdCode").val(categoryId);
			}
		},

		resetAdd: function(categoryType) {
			if (categoryType == "1") {
				$("#firstForm #isNew").val("Y");
				$("#firstForm #categoryId").val("");
				$("#firstForm #categoryNm").val("");
				$("#firstForm #categoryDesc").val("");
				$("#firstForm #menuGroupId").val("");
				$("#firstForm #useYn1").click();
			} else if (categoryType == "2") {
				$("#secondForm #isNew").val("Y");
				$("#secondForm #categoryId").val("");
				$("#secondForm #categoryNm").val("");
				$("#secondForm #categoryDesc").val("");
				$("#secondForm #menuGroupId").val("");
				$("#secondForm #useYn1").click();
			} else {
				$("#thirdForm #isNew").val("Y");
				$("#thirdForm #categoryId").val("");
				$("#thirdForm #categoryNm").val("");
				$("#thirdForm #categoryDesc").val("");
				$("#thirdForm #menuGroupId").val("");
				$("#thirdForm #useYn1").click();
			}
		},
		
		setDelete: function(categoryId, categoryType) {
			if (categoryType != "3") {
				this.getExist(categoryId, categoryType);
				if ($("#ajaxResult").val() > 0) {
					alert("해당 그룹에 속해 있는 코드가 있어 삭제가 불가능합니다.");
					return;
				}
			}
			
			if (!confirm("해당 카테고리를 삭제합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			var rParams = "target=cmDelete&categoryId=" + categoryId + "&" + $("#commonForm").serialize();

			this.makeList(url, rParams);
		},

		cancel: function(categoryType) {
			if (categoryType == "1") {
				$("#addFirstDiv").slideUp(100);
			} else if (categoryType == "2") {
				$("#addSecondDiv").slideUp(100);
			} else {
				$("#addThirdDiv").slideUp(100);
			}
			this.resetAdd(categoryType);
		},

		save: function(categoryType) {
			var categoryNm = "";
			var rParams = "target=cmSave&" + $("#commonForm").serialize();
			if (categoryType == "1") {
				categoryNm = $("#firstForm #categoryNm");
				rParams = rParams + "&" + $("#firstForm").serialize();
			} else if (categoryType == "2") {
				categoryNm = $("#secondForm #categoryNm");
				rParams = rParams + "&" + $("#secondForm").serialize();
			} else {
				categoryNm = $("#thirdForm #categoryNm");
				rParams = rParams + "&" + $("#thirdForm").serialize();
			}
			if (categoryNm.val() == "") {
				alert("카테고리 이름을 입력하여 주십시오.");
				categoryNm.focus();
				return;
			}
			
			if (!confirm("해당 설정을 저장합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			this.makeList(url, rParams);
		},
		
		getExist: function(categoryId, categoryType) {
			$.ajax({
				url : url,
				type : "POST",
				data : "target=mmExist&categoryId=" + categoryId + "&categoryType=" + categoryType,
				dataType : "html",
				async : false,
				success : function(data) {
					$("#ajaxResult").remove();
					$("body").append(data);
				}
			});
		},
		   
		makeList: function(sUrl, sParams) {
			var that = this;
			
			$.ajax({
				url : sUrl,
				type : "POST",
				data : sParams,
				dataType : "html",
				success : function(data){
					$("#" + targetElement).html(data);

					that.setUnbinding();
					that.setBinding();
					that.initPage();

					if ($("#nodata").html() != null) {
					}
				}
			});
		},
		
		initPage: function(){
			this.initPageSize();
		},
		     
		initPageSize: function(){
		    var msg = "";
			
			// warp
			var valueGwpw = getObjectValue("#warp", "width"); 
			var gwpw = (valueGwpw == null) ? 0 : valueGwpw; // 대상 전체 폭
			var valueGwph = getObjectValue("#warp", "height"); 
			var gwph = (valueGwph == null) ? 0 : valueGwph; // 대상 전체 높이
			msg = appendMessage(msg, "#warp");
			
			setObjectValue("#container", "width", Math.round(gwpw - 40));
			
			// container
			var valueGcw = getObjectValue("#container", "width"); 
			var gcw = (valueGcw == null) ? 0 : valueGcw; // 대상 전체 폭
			var valueGch = getObjectValue("#container", "height"); 
			var gch = (valueGch == null) ? 0 : valueGch; // 대상 전체 높이
			msg = appendMessage(msg, "#container");
			
			// contants
			setObjectValue("#contants", "width", Math.round(gcw - 180 - 10));
			msg = appendMessage(msg, "#contants");
			
			// formtitle
			var valueGftw = getObjectValue("#formtitle", "width");
			var gftw = (valueGftw == null) ? 0 : valueGftw; // 대상 전체 폭
			var valueGfth = getObjectValue("#formtitle", "height"); 
			var gfth = (valueGfth == null) ? 0 : valueGfth; // 대상 전체 높이
			
			// formlist
			var valueGccw = getObjectValue("#contants", "width"); 
			var gccw = (valueGccw == null) ? 0 : valueGccw; // 대상 전체 폭
			var valueGcch = getObjectValue("#contants", "height"); 
			var gcch = (valueGcch == null) ? 0 : valueGcch; // 대상 전체 높이

			setObjectValue("#formlist2l", "height", Math.round(gcch - gfth - 35));
			setObjectValue("#formlist2c", "height", Math.round(gcch - gfth - 35));
			setObjectValue("#formlist2r", "height", Math.round(gcch - gfth - 35));
			
			var formw = getObjectValue("#formlist2l", "width") + getObjectValue("#formlist2c", "width"); 
			setObjectValue("#formlist2r", "width", Math.round(gccw - formw - 30));
			msg = appendMessage(msg, "#formlist2r");
			
			$(".LoggingMessage").html(msg);
		}
};

$(document).ready(function(){
	pmModule.loadList();
	pmModule.initPage();
});

$(window).resize(function(){
	pmModule.initPage();
});
</script>
</body>
</html>
